﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2010
// admin@franknagl.de
//
namespace SBIP.OptionsForms
{
    using System;
    using System.Windows.Forms;
    using Filter;

    /// <summary>Filter specified properties form.</summary>
    public partial class SobelForm : Form
    {
        private readonly SobelEdgeDetector filter;

        /// <summary>
        /// Initializes a new instance of the <see cref="SobelForm"/> class.
        /// </summary>
        /// <param name="processor">The processor.</param>
        public SobelForm(Processor processor)
        {
            InitializeComponent();
            filter = new SobelEdgeDetector();
            processor.Filter = filter;
        }

        private void ThresholdTrackBarValueChanged(object sender, EventArgs e)
        {
            filter.Threshold = (byte)ThresholdTrackBar.Value;
            ThresholdValueLabel.Text = ThresholdTrackBar.Value.ToString();
        }

        private void RdbtnNormalCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.IsColored = false;
                filter.IsBlackWhite = false;
            }
        }

        private void RdbtnColoredCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.IsColored = true;
                filter.IsBlackWhite = false;
            }
        }

        private void RdbtnBlackWhiteCheckedChanged(object sender, EventArgs e)
        {
            if (((RadioButton)sender).Checked)
            {
                filter.IsColored = false;
                filter.IsBlackWhite = true;
                chbThreshold.Checked = true;
            }
        }

        private void ChbThresholdCheckedChanged(object sender, EventArgs e)
        {
            if (((CheckBox)sender).Checked)
            {
                ThresholdTrackBar.Visible = true;
                ThresholdTrackBarValueChanged(sender, e);
            }
            else
            {
                filter.Threshold = 0;
                ThresholdTrackBar.Visible = false;
                if (rdbtnBlackWhite.Checked)
                {
                    rdbtnNormal.Checked = true;
                }
            }
        }
    }
}
